package com.duleme.service.impl;

import com.duleme.dao.BookDao;
import com.duleme.dao.ShopDao;
import com.duleme.entity.Book;
import com.duleme.service.BookService;

import java.util.List;

public class BookServiceImpl implements BookService {
    @Override
    public List<Book> booksOfShop(int ownerId) {
        ShopDao shopDao=new ShopDao();
        BookDao bookDao=new BookDao();
        int shopId=shopDao.findShopIdByOwnerId(ownerId);
        if (shopId==-1){
            return null;
        }else{
            List<Book> list;
            list=bookDao.findBooksByShopId(shopId);
            return list;
        }
    }

    public BookServiceImpl() {
        super();
    }

    @Override
    public boolean addBookToShoppingCart(Book book) {
        return false;
    }

    @Override
    public boolean removeBookFromShoppingCart(int bookId) {
        return false;
    }

    @Override
    public boolean uploadNewBook(Book book) {
        boolean result=false;
        BookDao dao=new BookDao();
        result=dao.insertBook(book);
        return result;
    }

    @Override
    public Book getBook(int bookID) {
        BookDao bookDao = new BookDao();
        return bookDao.findBookByBookId(bookID);
    }

    public static void main(String[] args){
        BookService bookService = new BookServiceImpl();
        Book book = bookService.getBook(90);
        System.out.println(book.getBookName());
    }
}
